﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using System.Threading;

namespace sunt_AJAX_Demo.sunt_AjaxWebServices.Sunt_WebServecs
{
    /// <summary>
    /// sunt_AjaxWebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    //[System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
     //[System.Web.Script.Services.ScriptService]
    [ScriptService]
    public class sunt_AjaxWebService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        
        /// <summary>
        ///  返回一个随机数
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public int getRandom()
        {
            return new Random().Next(DateTime.Now.Millisecond);
        }

        /// <summary>
        /// 返回指定范围的随机数
        /// </summary>
        /// <param name="minValue">最小值</param>
        /// <param name="maxValue">最大值</param>
        /// <returns></returns>
        [WebMethod]
        public int GetRandomByRange(int minValue, int maxValue)
        {
            return new Random().Next(minValue, maxValue);
        }
        /// <summary>
        /// 获得两个数的商
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        [WebMethod]
        public int GetDivision(int a, int b)
        {
            return a / b;
        }
        /// <summary>
        /// 引发超时错误
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public int TimeOut()
        {
            Thread.Sleep(5000);
            return 0;
        }
    }
}
